import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { NestExpressApplication } from '@nestjs/platform-express';
import * as cookieParser from 'cookie-parser';

import { AllResponseInterceptor } from './all-response/all-response.interface';
import { AppModule } from './app.module';
import * as session from 'express-session';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  const config = new DocumentBuilder()
    .setTitle('接口') //标题
    .setDescription('服务器端API接口')//描述
    .setVersion('1.0')
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('cvnert', app, document);
  //session中间件
  app.use(session({
    secret: 'cvnert',
    resave: false,
    saveUninitialized: false,
  }))
  //cookie中间件
  app.use(cookieParser());
  //跨域
  app.enableCors({ origin: true, credentials: true });
  app.useGlobalInterceptors(new AllResponseInterceptor()); // 全局拦截器
  app.useStaticAssets('./public');
  app.useGlobalPipes(new ValidationPipe());
  await app.listen(3333);
}
bootstrap();
